package com.baichang.taoshunda.controller.mobile.business;

import com.baichang.framework.controller.BaseMobileController;
import com.baichang.framework.controller.IService;
import com.baichang.framework.excelption.ServiceException;
import com.baichang.taoshunda.controller.ControllerConstants;
import com.baichang.taoshunda.entity.Incidental;
import com.baichang.taoshunda.service.IncidentalService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Created by ${wushenglu} on 2018/3/22.
 */
@Controller
@RequestMapping(ControllerConstants.INCIDENTAL)
public class IncidentalController extends BaseMobileController {
    @Autowired
    private IncidentalService incidentalService;

    /**
     * 添加杂费记录
     *
     * @param request
     * @param response
     */
    @RequestMapping("/addIncidental")
    public void addIncidental(HttpServletRequest request, HttpServletResponse response) {
        initEncode(request, response, new IService() {
            @Override
            public Object init(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, String json) throws ServiceException {
                Integer busId = getInt(json, "busId", 0); //商家id
                String goodsId = getString(json, "goodsId", ""); //商品编号   互动编号
                Integer type = getInt(json, "type", 0);//1商品视频2互动发布
                Integer payMethod = getInt(json, "payMethod", 1);//1   支付宝   2微信
                double money = getDouble(json, "money", 0);//缴费金额
                return incidentalService.addIncidental(busId, type, money, goodsId, payMethod);
            }
        });
    }

    /**
     * 订单支付
     */
    //TODO 回调
    @RequestMapping("/payInfo")
    public void payOrder(HttpServletRequest request, HttpServletResponse response) {
        initEncode(request, response, new IService() {
            @Override
            public Object init(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, String json) throws ServiceException {
                Integer typeId = getInteger(json, "typeId", 0);//1商品视频2互动发布
                int payMethod = getInt(json, "payMethod", 0);
                return incidentalService.payInfo(typeId, payMethod);
            }
        });
    }
}
